package com.water.controller;

import com.water.pojo.Team;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author wsj
 * @version 1.0
 * @description: TODO
 * @date 2022/2/12 11:28
 */
@Controller
@RequestMapping("result")
public class ResultController {

    //modelandview 返回模型和视图
    @RequestMapping("/test01")
    public ModelAndView test01(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("teamName","湖人队");
        mv.setViewName("result"); //视图解析器，拼接成物理url地址
        return mv;
    }


    @RequestMapping("/test2")
    public String test2(HttpServletRequest request){
        Team team = new Team();
        team.setName("热火队");
        team.setId(12233);
        request.setAttribute("team",team);
        request.getSession().setAttribute("team",team);
        return "result"; //也是跳转到拼接后的物理地址
    }

    //前后端分离，body，json数据格式，响应体返回，ajax处理
    @ResponseBody
    @RequestMapping("/test3")
    public Team test3(){
        Team team = new Team();
        team.setCreateTime(new Date());
        team.setId(122);
        team.setName("篮网队");
        team.setLocation("布林克林");
        return team;
    }


}
